package com.bootdo.jiashan.service.impl;

import com.bootdo.common.utils.BeanCopierUtil;
import com.bootdo.common.utils.DateUtil;
import com.bootdo.jiashan.model.ProductModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.bootdo.jiashan.dao.ProductDao;
import com.bootdo.jiashan.domain.ProductDO;
import com.bootdo.jiashan.service.ProductService;
import org.springframework.util.CollectionUtils;

import static com.bootdo.common.utils.DateUtil.dateTimeFormatter;


@Service
public class ProductServiceImpl implements ProductService {
	@Autowired
	private ProductDao productDao;
	
	@Override
	public ProductDO get(Integer id){
		return productDao.get(id);
	}
	
	@Override
	public List<ProductModel> list(Map<String, Object> map){
		List<ProductModel> modelList = new ArrayList<>();
		List<ProductDO> doList = productDao.list(map);
		if(!CollectionUtils.isEmpty(doList)){
			doList.forEach(productDO -> {
				ProductModel model = new ProductModel();
				BeanCopierUtil.copyProperties(productDO,model);
				modelList.add(model);
			});
		}
		return modelList;
	}
	
	@Override
	public int count(Map<String, Object> map){
		return productDao.count(map);
	}
	
	@Override
	public int save(ProductDO product){
		product.setCtime(System.currentTimeMillis());
		return productDao.insertSelective(product);
	}
	
	@Override
	public int update(ProductDO product){
		product.setUtime(System.currentTimeMillis());
		return productDao.update(product);
	}
	
	@Override
	public int remove(Integer id){
		return productDao.remove(id);
	}
	
	@Override
	public int batchRemove(Integer[] ids){
		return productDao.batchRemove(ids);
	}
	
}
